import { Component, OnInit } from '@angular/core';
import { PageService } from 'app/utils/page.service'
import { ReportManageService } from 'app/services/report/report-manage.service'


@Component({
  selector: 'app-report-manage',
  templateUrl: './report-manage.component.html',
  styleUrls: ['./report-manage.component.less']
})
export class ReportManageComponent implements OnInit {

  dataSet: Array<any> = []

  constructor(
    private page: PageService,
    private reportManageService: ReportManageService
  ) { }

  ngOnInit() {
    this.refreshData()
  }

  /**
   * 更新数据
   */
  refreshData() {
    this.reportManageService.getReports()
      .then((data: Array<any>) => data.map(x => {
        let team = x.get('team')
        let user = team.get('admin')

        return {
          id: x.id,
          start: x.get('start'),
          end: x.get('end'),
          team: team.get('name'),
          admin: user.get('realname'),
          createdAt: x.createdAt
        }
      }))
      .then(data => {
        this.dataSet = data
      })
  }
}
